ENT.Spawnable			= false
ENT.AdminSpawnable		= false

include( "shared.lua" )

function ENT:Draw()
	self.Entity:DrawModel()
end

local Explosive_Debris = {};
local explosive_entities_sunbeams = CreateClientConVar( "explosive_entities_sunbeams", "1", true, false )

local function DrawSB()
	if ( !explosive_entities_sunbeams:GetBool() ) then return end
	for k, v in ipairs( Explosive_Debris )do
		if( v && v:IsValid() )then
			local posraw = v:GetPos()
			local pos = posraw:ToScreen() 
			if not (( pos.x < -300) or (pos.x > ScrW() + 300) or (pos.y < -300) or (pos.y > ScrH() + 300) ) then
			DrawSunbeams( 0, 0.007, 0.02, pos.x / ScrW(), pos.y / ScrH()) 
			end
		else
			table.remove( Explosive_Debris, k );
		end
	end
end
hook.Add( "RenderScreenspaceEffects", "SunBeamsForExplosiveEntities", DrawSB );

function ENT:Initialize()
	self.emitter = ParticleEmitter( self:GetPos() )
	table.insert( Explosive_Debris, self.Entity );
end

function ENT:Think()

	local LowSmoke, HighSmoke = self.Entity:WorldSpaceAABB()
	local CenterSmoke = HighSmoke - (( HighSmoke - LowSmoke ) / 5 )
	local vOffsetSmoke = Vector( math.Rand(LowSmoke.x,HighSmoke.x), math.Rand(LowSmoke.y,HighSmoke.y), math.Rand(LowSmoke.z,HighSmoke.z) )
	
	
	local LowFire, HighFire = self.Entity:WorldSpaceAABB()
	local CenterFire = HighFire - (( HighFire - LowFire ) / 5 )
	local vOffsetFire = Vector( math.Rand(LowFire.x,HighFire.x), math.Rand(LowFire.y,HighFire.y), math.Rand(LowFire.z,HighFire.z) )
	
	local vNormalSmoke = (vOffsetSmoke - self.Entity:GetPos()):GetNormalized()
	
	local vNormalFire = (vOffsetFire - self.Entity:GetPos()):GetNormalized()
	
	local SIZE = math.Clamp( self.Entity:BoundingRadius() + math.Rand( 0, 20 ), 10, 1000 )
				
		local particle2 = self.emitter:Add( "modulus/particles/Fire"..math.random(1,8), vOffsetFire  ) 
			  particle2:SetVelocity( vNormalFire * 1000 )
			  particle2:SetAirResistance( 1000 )
			  particle2:SetDieTime( 0.5 )
			  particle2:SetStartAlpha( 255 )
			  particle2:SetStartSize( SIZE )
			  particle2:SetEndSize( SIZE * 2 )
			  particle2:SetRoll( math.Rand( -5, 5 ) )
			  particle2:SetColor( 255, 255, 255 )
			  --particle2:SetLighting( true )
				
	    local particle = self.emitter:Add( "modulus/particles/Smoke"..math.random(1,6), vOffsetSmoke ) 
		      particle:SetVelocity( vNormalSmoke * math.Rand( 10, 20 ) )
		      particle:SetDieTime( math.Rand( 5, 10 ) )
		  	  particle:SetStartAlpha( 255 )
			  particle:SetStartSize( SIZE )
			  particle:SetEndSize( SIZE * 4 )
			  particle:SetRoll( math.Rand( -5, 5 ) )
			  particle:SetLighting( true )
			 
	return true
end

function ENT:OnRemove()
	self.emitter:Finish()
end